import ResMgr from "../../common/res/ResMgr";

const {ccclass, property} = cc._decorator;

@ccclass
export default class SceneUi extends cc.Component {

    @property(cc.Node)
    sceneLayer:cc.Node = null;
    @property(cc.Node)
    dialogLayer:cc.Node = null;
    @property(cc.Node)
    tipLayer:cc.Node = null;
    @property(cc.Node)
    loadLayer:cc.Node = null;
    @property(cc.Prefab)
    LoadUi:cc.Prefab = null;
    @property(cc.Prefab)
    TipUi:cc.Prefab = null;
    /**
     * 场景ui的实例
     */
    private static instance:SceneUi = null;
    
    onLoad () {
        SceneUi.instance = this;
    };
    start () {
        // load转圈
        cc.instantiate(this.LoadUi).parent = this.loadLayer;
        // tip
        cc.instantiate(this.TipUi).parent = this.tipLayer;
        // 加载登录场景
        ResMgr.insPrefab("ui/login/LoginUi", (node)=>{
            node.parent = this.sceneLayer;            
        });
    };
    // 进入登录界面
    public static enterLogin () {
        ResMgr.insPrefab("ui/login/LoginUi", (node)=>{
            SceneUi.instance.sceneLayer.destroyAllChildren();
            node.parent = SceneUi.instance.sceneLayer;
        });
    };
    // 进入游戏
    public static enterMain () {
        ResMgr.insPrefab("ui/main/MainUi", (node)=>{
            SceneUi.instance.sceneLayer.destroyAllChildren();
            node.parent = SceneUi.instance.sceneLayer;
        });
    };
    // 进入房间
    public static enterGame () {
        ResMgr.insPrefab("ui/game/GameUi", (node)=>{
            SceneUi.instance.sceneLayer.destroyAllChildren();
            node.parent = SceneUi.instance.sceneLayer;
        });
    };
}
